/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package classes;

import java.text.DecimalFormat;

/**
 * This class calculates the valuta to the chosen language correctly; It can
 * also return the sign separately and the currency of the valuta.
 *
 * @author Sander
 */
public class Valuta {

    private static Valuta exchanges[] = {
        new Valuta("pound", "&pound;", 0.8)
    };
    private String currency;
    private String sign;
    private double exchange;

    public Valuta() {
    }

    public Valuta(String currency, String sign, double exchange) {
        this.currency = currency;
        this.sign = sign;
        this.exchange = exchange;
    }

    public String getCurrency() {
        return currency;
    }

    public String getSign() {
        return sign;
    }

    public double getExchange() {
        return exchange;
    }

    /**
     * This method returns the exchange of the chosen language on the site; Only
     * for the pound he needs to replace the ',' (comma) for a '.' (dot).
     *
     * @param currency
     * @param exchange
     * @return
     */
    public static String calculateToCurrency(String currency, double exchange) {
        DecimalFormat df = new DecimalFormat("0.00");
        for (int i = 0; i < exchanges.length; i++) {
            if (exchanges[i].getCurrency().equals(currency)) {
                if (currency.equals("pound")) {
                    return df.format(exchange * exchanges[i].getExchange()).replace(',', '.');
                }
                return df.format(exchange * exchanges[i].getExchange());
            }
        }
        return df.format(exchange);
    }

    /**
     * This method returns the correct sign for the chosen language on the site;
     * It goes through all the valuta and when he matches one it will return
     * it's sign.
     *
     * @param currency
     * @return
     */
    public static String getSignFromCurrency(String currency) {
        for (int i = 0; i < exchanges.length; i++) {
            if (exchanges[i].getCurrency().equals(currency)) {
                return exchanges[i].getSign() + " ";
            }
        }
        return "&euro; ";
    }
}
